//
//  MenuView.m
//  CrazyDice
//
//  Created by Tony Wang on 9/13/10.
//  Copyright 2010 Exoweb. All rights reserved.
//

#import "MenuView.h"


@implementation MenuView


- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        // background
		bgImage = [[UIImageView alloc] initWithFrame:frame];
		[bgImage setImage:[UIImage imageNamed:@"background.png"]];
		bgImage.opaque = YES;
		
		// dice background
		diceBgImage = [[UIImageView alloc] initWithFrame:frame];
		[diceBgImage setImage:[UIImage imageNamed:@"dice-background.png"]];
		diceBgImage.opaque = YES;
		
		// play button
		playBtnRect = CGRectMake(47, 175, 226, 77);
		playBtn = [[UIImageView alloc] initWithFrame:playBtnRect];
		[playBtn setImage:[UIImage imageNamed:@"play-btn.png"]];
		playBtn.opaque = YES;
		
		// about button
		aboutBtnRect = CGRectMake(47, 275, 226, 77);
		aboutBtn = [[UIImageView alloc] initWithFrame:aboutBtnRect];
		[aboutBtn setImage:[UIImage imageNamed:@"about-btn.png"]];
		aboutBtn.opaque = YES;
		
		[self showMenu];
    }
    return self;
}

- (void)showMenu {
	[self addSubview:bgImage];
	[self addSubview:playBtn];
	[self addSubview:aboutBtn];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
	if (CGRectContainsPoint(playBtnRect, (CGPoint)[[touches anyObject] locationInView:self])) {
		for (UIView *subview in self.subviews) {
			[subview removeFromSuperview];
		}
		EAGLView *glView = [[EAGLView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
		glView.opaque = NO;
		[self addSubview:diceBgImage];
		[self addSubview:glView];
		[glView startAnimation];
		[glView release];
	} else {
		NSLog(@"out");
	}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)dealloc {
	//[background release];
	//background = nil;
	
    [super dealloc];
}


@end
